package com.woniu.darryringmall.front.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.darryringmall.front.entity.Agreement;
import com.woniu.darryringmall.front.service.AgreementService;
import com.woniu.darryringmall.utils.ResponseData;
import com.woniu.darryringmall.utils.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("front/agreement")
public class AgreementController {

    @Autowired
    private AgreementService agreementService;

    @PostMapping("add")
    public ResponseData add(@RequestBody Agreement agreement){
        agreement.setStatus("n");
        agreementService.save(agreement);
        return ResponseUtils.SUCCESS;
    }

    @PostMapping("select")
    public ResponseData select(@RequestBody Agreement agreement){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("IDCard",agreement.getIDCard());
        queryWrapper.eq("boyName",agreement.getBoyName());
        queryWrapper.eq("status","y");
        Agreement agree = agreementService.getOne(queryWrapper);
        if(agree==null){
            return new ResponseData(200,"还未购买戒指");
        }
        return new ResponseData(400,"已购买戒指，无法再购买");
    }
}
